home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cocktail
/
front.lha
/
front
/
src
/
Actions.mi
< prev
next >
Wrap
Text File
|
1992-08-18
|
5KB
|
190 lines
(* hanlde global actions and comments *)
(* $Id: Actions.mi,v 1.5 1992/08/07 15:13:51 grosch rel $ *)
(* $Log: Actions.mi,v $
* Revision 1.5 1992/08/07 15:13:51 grosch
* allow several scanner and parsers; extend module Errors
*
* Revision 1.4 1991/12/04 16:21:41 grosch
* unified escape conventions for all tools
*
* Revision 1.3 1991/11/21 14:47:50 grosch
* new version of RCS on SPARC
*
* Revision 1.2 90/06/11 18:44:36 grosch
* layout improvements
*
* Revision 1.1 89/01/12 18:07:10 vielsack
* line number is printed before an action is output
*
* Revision 1.0 88/10/04 14:26:33 vielsack
* Initial revision
*
*)
IMPLEMENTATION MODULE Actions;
FROM IO IMPORT WriteC, WriteS, WriteI, WriteNl, tFile;
FROM Lists IMPORT MakeList, IsEmpty, Head, Tail, tList;
FROM Memory IMPORT Alloc;
FROM Strings IMPORT Char, Length, tStringIndex, tString;
FROM StringMem IMPORT GetString, tStringRef, WriteString;
FROM SYSTEM IMPORT TSIZE;
FROM TokenTab IMPORT PosType;
FROM WriteTok IMPORT tLanguage, Language, SourceFileName;
TYPE
ElmtType =
RECORD
Act : tList;
ActPos : PosType;
Comm : tList;
CommPos : PosType;
END;
VAR
ActionMode : tActionMode;
KeyPos : ARRAY tActionMode OF PosType;
Action : ARRAY tActionMode OF ElmtType;
ActionComm : ARRAY tActionMode OF tList;
ActionCommPos : ARRAY tActionMode OF PosType;
dummyPos : PosType;
PROCEDURE PutComment (kind: tActionMode; kp: PosType; c: tList; cp: PosType);
BEGIN
KeyPos [kind] := kp;
ActionComm [kind] := c;
ActionCommPos [kind] := cp;
END PutComment;
PROCEDURE GetComment (kind: tActionMode; VAR kp: PosType; VAR c: tList; VAR cp: PosType);
BEGIN
kp := KeyPos [kind];
c := ActionComm [kind];
cp := ActionCommPos [kind];
END GetComment;
PROCEDURE PutAction (kind: tActionMode; a: tList; ap: PosType; c: tList; cp: PosType);
BEGIN
WITH Action [kind] DO
Act := a;
ActPos := ap;
Comm := c;
CommPos := cp;
END;
END PutAction;
PROCEDURE GetAction (kind: tActionMode; VAR a: tList; VAR ap: PosType; VAR c: tList; VAR cp: PosType);
BEGIN
WITH Action [kind] DO
a := Act;
ap := ActPos;
c := Comm;
cp := CommPos;
END;
END GetAction;
PROCEDURE WriteActions (kind: tActionMode; f: tFile; Line: BOOLEAN);
BEGIN
IF Action [kind].ActPos.Line # 0 THEN
IF Language = Modula2 THEN
WriteS (f, '(* line ');
WriteI (f, Action [kind].ActPos.Line, 0);
WriteS (f, ' "');
WriteS (f, SourceFileName);
WriteS (f, '" *)');
WriteNl (f);
ELSE (* Language = C *)
IF Line THEN
WriteS (f, '# line ');
WriteI (f, Action [kind].ActPos.Line, 1);
WriteS (f, ' "');
WriteS (f, SourceFileName);
WriteC (f, '"');
WriteNl (f);
ELSE
WriteS (f, '/* line ');
WriteI (f, Action [kind].ActPos.Line, 1);
WriteS (f, ' "');
WriteS (f, SourceFileName);
WriteS (f, '" */');
WriteNl (f);
END;
END;
END;
WriteSemanticAction (f, Action [kind].Act, 0);
END WriteActions;
PROCEDURE WriteSemanticAction (f: tFile; a: tList; t: CARDINAL);
VAR
c : CHAR;
s : tString;
i : tStringIndex;
i1, i2 : tStringIndex;
Delimiter : CHAR;
PROCEDURE Tab;
BEGIN
FOR i := 1 TO t DO
WriteC (f, ' ');
WriteC (f, ' ');
END;
END Tab;
BEGIN
i1 := 2; (* Erstes Zeichen des ersten Strings ist Randbegrenzung *)
WHILE NOT IsEmpty (a) DO
GetString (tStringRef (Head (a)), s);
Tail (a);
i2 := Length (s);
IF IsEmpty (a) THEN
DEC (i2); (* letztes Zeichen des letzten Strings ist Randbegrenzung *)
END;
Tab;
i := i1;
WHILE i <= i2 DO
c := Char (s, i); INC (i);
IF c = '\' THEN
WriteC (f, Char (s, i)); INC (i);
ELSIF (c = '"') OR (c = "'") THEN
Delimiter := c;
WriteC (f, c);
REPEAT
c := Char (s, i); INC (i);
WriteC (f, c);
IF (Language = C) AND (c = '\') THEN
WriteC (f, Char (s, i)); INC (i);
END;
UNTIL c = Delimiter;
ELSE
WriteC (f, c);
END;
END;
i1 := 1;
END;
WriteNl (f);
END WriteSemanticAction;
PROCEDURE WriteStringList (file: tFile; slist: tList);
BEGIN
WHILE NOT IsEmpty (slist) DO
WriteString (file, tStringRef (Head (slist)));
Tail (slist);
END;
END WriteStringList;
BEGIN
dummyPos.Line := 0;
dummyPos.Column := 0;
FOR ActionMode := MIN (tActionMode) TO MAX (tActionMode) DO
KeyPos [ActionMode] := dummyPos;
MakeList (ActionComm [ActionMode]);
ActionCommPos [ActionMode] := dummyPos;
MakeList (Action [ActionMode].Act);
Action [ActionMode].ActPos := dummyPos;
MakeList (Action [ActionMode].Comm);
Action [ActionMode].CommPos := dummyPos;
END;
END Actions.